#ifndef TASK_H
#define TASK_H
#include <stdint.h>
#include "./linkedList.h"

#ifdef __cplusplus
extern "C" {
#endif

extern uint16_t task_oneTime;
extern uint32_t task_times;
typedef enum {
  taskStatus_ready = 0x61,   //准备执行
  taskStatus_run = 0x66,     //正在执行
  taskStatus_finish = 0x6F,  //执行完成
  taskStatus_stop = 0xF0,    //停止执行
  taskStatus_error = 0xFF,   //未知错误
} Task_Status;               //状态码
typedef struct {
  uint16_t uid;        //唯一ID
  Task_Status status;  //当前状态
  uint32_t startTime;  //开始时间
  uint32_t endTime;    //结束时间
  void (*func)(void);  //执行函数
  uint16_t times;      //执行次数
  uint16_t timesRun;   //已执行次数
  uint16_t interval;   //执行间隔 0每次main函数都执行
} Task_Struct;         //任务结构体

void task_init(uint16_t nms);
void task_add(uint16_t uid, void (*func)(void), uint16_t in);
void task_start(uint16_t uid, uint16_t ts, uint16_t st, uint16_t et);
void task_stop(uint16_t uid);
void task_cmd(uint16_t uid, Task_Status status);
void task_tick(void);
void task_run(void);

#ifdef __cplusplus
}
#endif
#endif  // TASK_H
